import 'package:shared_preferences/shared_preferences.dart';
import '../lib/shared/services/storage_service.dart';
import '../lib/shared/models/learning_record.dart';

void main() async {
  print('Testing storage functionality...');
  
  // 初始化SharedPreferences
  final prefs = await SharedPreferences.getInstance();
  final storage = StorageService();
  await storage.init();
  
  // 测试添加掌握词汇
  print('\n1. Testing mastered words...');
  await storage.addMasteredWord('test_word_1');
  await storage.addMasteredWord('test_word_2');
  
  final masteredWords = await storage.getMasteredWords();
  print('Mastered words: ${masteredWords.toList()}');
  
  // 测试学习记录
  print('\n2. Testing learning records...');
  final record = LearningRecord(
    id: 'test_record_1',
    wordId: 'test_word_1',
    studiedAt: DateTime.now(),
    isCorrect: true,
    difficulty: '1',
  );
  
  await storage.addLearningRecord(record);
  
  final records = await storage.getLearningRecords();
  print('Learning records count: ${records.length}');
  if (records.isNotEmpty) {
    print('Latest record: ${records.last.wordId} - ${records.last.isCorrect}');
  }
  
  // 测试学习索引
  print('\n3. Testing learning index...');
  await storage.saveCurrentLearningIndex(10);
  final currentIndex = await storage.getCurrentLearningIndex();
  print('Current learning index: $currentIndex');
  
  // 调试输出
  print('\n4. Debug output:');
  await storage.debugPrintStoredData();
  
  print('\nStorage test completed!');
} 